/*
 * AccountSettingsFrame.cpp
 *
 *  Created on: 15.07.2009
 *      Author: h3llfire
 */

#include "AccountSettingsFrame.h"
#include "../../core/Impp.h"

namespace Impp {

BEGIN_EVENT_TABLE(AccountSettingsFrame, wxDialog)
	EVT_BUTTON(wxID_OK, AccountSettingsFrame::onOk)
	EVT_BUTTON(wxID_CANCEL, AccountSettingsFrame::onCancle)
END_EVENT_TABLE()

AccountSettingsFrame::AccountSettingsFrame(wxWindow* parent, Account* acc) :
	wxDialog(parent, (wxWindowID)wxID_ANY, wxString(wxT("Account Settings"))),
	acc(acc){

	wxString screenname;
	wxString password;

	if(acc != NULL){
		screenname = acc->screenname;
		password = acc->password;
	}

	wxBoxSizer* mainSizer = new wxBoxSizer(wxVERTICAL);

	wxPanel* mainPane = new wxPanel(this);


	//cbProtocol = new wxComboBox(mainPane, wxID_ANY, )

	wxGridSizer* fieldSizer = new wxGridSizer(2,2,5,5);


	wxStaticText* labScreenName = new wxStaticText(mainPane,wxID_ANY,_T("Account-Name (ICQ No):"));
	fieldSizer->Add(labScreenName,1,wxALL, 5);

	txtScreenName = new wxTextCtrl(mainPane,wxID_ANY,screenname,wxDefaultPosition,wxDefaultSize,0,wxTextValidator(wxFILTER_ALPHANUMERIC|wxFILTER_NUMERIC));
	fieldSizer->Add(txtScreenName,1,wxALL|wxEXPAND, 5);

	wxStaticText* labPw = new wxStaticText(mainPane,wxID_ANY,_T("Password: "));
	fieldSizer->Add(labPw,1,wxALL, 5);

	txtPW = new wxTextCtrl(mainPane,wxID_ANY,password,wxDefaultPosition,wxDefaultSize,wxTE_PASSWORD);
	fieldSizer->Add(txtPW,1,wxALL|wxEXPAND, 5);

	mainSizer->Add(fieldSizer, 1, wxALL, 20);

	wxButton* btOK = new wxButton(mainPane, wxID_OK);
	wxButton* btCancle = new wxButton(mainPane, wxID_CANCEL);

	wxBoxSizer* buttonSizer = new wxBoxSizer(wxHORIZONTAL);
	buttonSizer->Add(btOK, 1, wxALL, 5);
	buttonSizer->Add(btCancle, 1, wxALL, 5);

	mainSizer->Add(buttonSizer, 1, wxALL, 20);

	mainPane->SetSizer(mainSizer);
	Layout();
}

void AccountSettingsFrame::onOk(wxCommandEvent& event){
	if(acc != NULL){
		//don't create a new one, use the exsisting
		Impp::exemplar()->changeAccountInfo(acc->id, txtScreenName->GetValue(), txtPW->GetValue());
	}else{
		Impp::exemplar()->createAccount(wxT("Oscar"), txtScreenName->GetValue(), txtPW->GetValue());
	}
	EndModal(wxID_OK);
}
void AccountSettingsFrame::onCancle(wxCommandEvent& event){
	EndModal(wxID_CANCEL);
}

AccountSettingsFrame::~AccountSettingsFrame() {

}

}
